#!/bin/sh
ha=$1
hot=$2
fpath=$3
i=$4

while :
do
    case "$i" in
        0 )
            url="http://178.73.198.210/torrent/"$ha".torrent";;
        1)
            s=${ha:0:2}
            e=${ha:0-2:2}
            url="http://bt.box.n0808.com/"$s"/"$e"/"$ha".torrent";;
        2)
            url="http://btdig.com/"$ha".torrent";;
        3)
            url="http://thetorrent.org/"$ha".torrent";;
        4)
            url="https://torcache.net/torrent/"$ha".torrent";;
        *)
            echo "NO"
            exit 2
    esac

    `wget --no-check-certificate -q -O $fpath $url`

    if [ ! -f "$fpath" ]; then
        $i=$[$i+1]
        continue
    else
        str=`cat $fpath | grep "html"`
        len=`ls -l $fpath | awk '{print $5}'`
        if [ ! -n "$str" ]; then
            if [ "$len" -gt 1024 ]; then
                echo "OK"
                break
            fi
        fi
    fi
    i=$[$i+1]
done